from configobj import ConfigObj
import configparser
config = ConfigObj("/home/he/hellobot/src/config.ini",encoding='UTF8')
# 读配置文件
print(config['imu'])

pin_left = config['wheels']['pin_left']
print('the wheel radius is: '+pin_left)

##############

configPath = "/home/he/hellobot/src/config.ini"#获取配置文件的路径

conf=configparser.ConfigParser()#创建对象用于对配置文件进行操作
conf.read(configPath,encoding="utf-8-sig")#以utf8编码形式读取

# return all section
secs = conf.sections()     # 获取sections，返回list
print('sections:', secs, type(secs))
 
opts = conf.options("wheels")  # 获取section下的 options，返回list
print('options:', opts, type(opts))
 
# 获取section 下的所有键值对，返回list 如下，每个list元素为键值对元组
kvs = conf.items("wheels")
print('wheels:', kvs)
 
# read by type 类似的有 getboolean() getfloat()
left = conf.get("wheels", "pin_left")
right = conf.getint("wheels", "pin_right")

print('the leftwheel is on: '+left+'\n')
print('the rightwheel is on %2.1f \n'%right)
